// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
// jsdoc语法提示教程：https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129
let dbJQL;
module.exports = {
	_before: function() { // 通用预处理器
		if (!this.getUniIdToken()) {
			
			throw new Error('请登录后查看')
			
		}
		const params = this.params;

		dbJQL = uniCloud.databaseForJQL({ // 获取JQL database引用，此处需要传入云对象的clientInfo
			clientInfo: this.getClientInfo()
		})
		dbJQL.setUser({
			uid: '6651d8f781173e5df6bd55a2',
			role: ['admin']
		})
	},
	async getGoodsList({
		_id,
		page = 1
	}) {
		const result = await dbJQL.collection('opendb-mall-goods').where({category_id:_id}).field('_id,name,goods_code as code,goods_thumb as image').skip(18 * (page - 1)).limit(18)
			.orderBy("sort", "asc").get({
				getCount: true
			});
		return result;
	},
	async getGoodsInfo(goods_id){
		const result = await dbJQL.collection('opendb-mall-goods').where({_id:goods_id}).get({getOne:true});
		return result;
	}
}